//本地测试环境
//var queryUrl ="http://localhost:8080/ceairweb/";
//测试环境
//var queryUrl ="http://flymt.ceair.com/ceairweb/";
//正式地址
var queryUrl ="http://mpservice.ceair.com/ceairweb/";
//测试地址
//var queryUrl ="http://mgstest.ceair.com:8080/ceairweb/";
var iG = {};
iG.versionNo = '202022';
iG.debug = false;
/* 操作数据
---------------------------------------------------------------------------------------*/
//自动装载数据
iG.autoData = function(obj,wrapElem){
    if(wrapElem == undefined) wrapElem = $("body");
    wrapElem.find("[auto]").each(function(){
        var key = $(this).attr("auto");
        var objCopy = obj;
        while (key.indexOf("_") != "-1") {
            var sep = key.indexOf("_");
            objCopy = objCopy[key.substring(0, sep)];
            key = key.substring(key.indexOf("_") + 1);
        };
        if (objCopy != null) {
			if(objCopy[key]!=null){
				 $(this).text(objCopy[key].toUpperCase());
			}
        }else{
			 $(this).text("--");
		}
    });
};
/* 操作本地存储
---------------------------------------------------------------------------------------*/
//获取本地存储obj值
//获取本地存储obj值
iG.getObjItem = function(obj,key){
    var json = localStorage.getItem(obj);
    if(json == null || json == undefined || json == "undefined" || json == ""){
		return undefined;
	}else{
		json=JSON.parse(json);
	}
    return json[key];
};
//设置本地存储obj值
iG.setObjItem = function(obj,key,value){
    var json = localStorage.getItem(obj);
    if(json == null || json == undefined || json == "undefined" || json == ""){
		json = {};
	}else{
		json=JSON.parse(json);
	}
    json[key] = value;
    localStorage.setItem(obj,JSON.stringify(json));
};
//删除本地存储obj值
iG.removeObjItem = function(obj,key){
    var json = localStorage.getItem(obj);
    if(json == null || json == undefined || json == "undefined" || json == ""){
		return;
	}else{
		json=JSON.parse(json); 
	}
    delete json[key];
    localStorage.setItem(obj,JSON.stringify(json));
};

//本地存储
var lcstor = window.localStorage;
function setStorage(key, value) {
    if (lcstor)
        lcstor[key] = value;
    //else 
    //alert('localStorage error');
}

function getStorage(key) {
    if (lcstor) {
        for (i in lcstor) {
            if (i == key)
                return lcstor[i];
        }
    }
    //else 
    //alert('localStorage error');
}
/* 设置页面回弹
---------------------------------------------------------------------------------------*/
//默认状态
iG.setBounce = function(){
    uexWindow.setBounce("1");
    uexWindow.showBounceView("0","#f4f4f4","0");
    uexWindow.showBounceView("1","#f4f4f4","0");
    uexWindow.notifyBounceEvent("0","0");
};
//下拉刷新
iG.pullDown = function(callback){
    var j = {
        "pullToReloadText":"下拉刷新",
        "releaseToReloadText":"释放立即刷新",
        "loadingText":"正在刷新...",
        "loadingImagePath":"res://shuaxin.png"
    };
    if(!uexWindow.setBounce)
        return;
    uexWindow.setBounce("1");
    uexWindow.setBounceParams('0',JSON.stringify(j));
    uexWindow.showBounceView("0","#f4f4f4",1);
//    uexWindow.showBounceView("1","#f4f4f4",0);
    uexWindow.notifyBounceEvent("0","1");
    uexWindow.onBounceStateChange = function(type,status){
        if(type==0 && status==2) {
            callback();
        }
    }
};
/* 其他
---------------------------------------------------------------------------------------*/
//记录打开窗口
iG.saveOpenWin = function(winName){
    var array = iG.getObjItem("openWin","array");
    if(array.indexOf(winName) == -1){
        array.push(winName);
    }
    iG.setObjItem("openWin","array",array);
};
//打开新窗口
iG.openWin = function(name,data){
   /* if(!iG.checkAuthortization("window",name)){
        uexWindow.alert("提示","很抱歉，您没有相关权限！","确定");
        return false;
    }*/
    if(data){
        localStorage.setItem(name,JSON.stringify(data));
    }
    var url = name + ".html";
    iG.saveOpenWin(name);
    uexWindow.open(name,0,url,2,"","","4",280);
};

//页面提示
iG.tip = function(msg, tipId){
    var html = '<div class="uba p10 uc-a5 c17 tx-c">'+ msg +'</div>';
    if (tipId) {
        $("#" + tipId).empty().addClass("p8").append(html);
    }
    else {
        $("body").empty().addClass("p8").append(html);
    }
};

//请求回调
iG.ajaxCallback = function(isRefresh){
    if(isRefresh){
        uexWindow.resetBounceView('0');
    }else{
        $.iBoxHide();
    }
};

//是否显示
iG.isShow = function(type){
    $("[showAt]").each(function(){
        var array = $(this).attr("showAt").split(",");
        for(var i in array){
            if(type == array[i]){
                $(this).removeClass("uhide");
                return;
            }
        }
        $(this).addClass("uhide");
    })
    $("[hideAt]").each(function(){
        var array = $(this).attr("hideAt").split(",");
        for(var i in array){
            if(type == array[i]){
                $(this).addClass("uhide");
                return;
            }
        }
        $(this).removeClass("uhide")
    })
};
//固定字符串
iG.fixed = function(){
    $("[fixed]").each(function(){
        var txt = $(this).text();
        $(this).text(txt.substring(0,2))
    })
};
//滚动
iG.scroll = function(wrap,speedVal){
    var speed = speedVal || 50;
    var that = arguments.callee;
    var width = wrap.width();
    var child = wrap.children();
    var childWidth = child.width();
    var time = parseInt(width + childWidth) * 1000 / speed;

    if(childWidth<= width)return;
    wrap.css("box-pack","start");
    child.css("left",width).animate({"left":-childWidth},time,"linear",function(){
        that(wrap,speed);
    })
};

//debug
if(window.navigator.platform=="Win32" && iG.debug){
    document.write('<script src="../js/debug.js?v=202013"></script>')
};

/**
 * 获取掌上东航定位信息
 */
function setLocalLocation(){
	var uAddress = localStorage['uAddress'];
//    var uAddress = "ddd&loc=陕西省西安市莲湖区";
	if (uAddress != undefined) {
		var uAddressArr = uAddress.split("loc=");
		
        uAddress = decodeURIComponent(uAddressArr[1]);
		if(uAddress.indexOf("省")>0)
		{
			uAddressArr = uAddress.split("省");
            uAddress = uAddressArr[1];
			uAddressArr = uAddress.split("市");
            uAddress = uAddressArr[0];
		}
		else
		{
			 uAddressArr = uAddress.split("市");
           	 uAddress = uAddressArr[0];
		}
        if (uAddress == undefined || uAddress == "" || uAddress == null) {
        	uAddress = "上海";
        }
	     loadInfo(uAddress);
	}
    else {	
        $$("qifei").innerHTML = "上海虹桥";
		$$("qifei1").innerHTML =  "SHA";
    }
}
//加载城市信息
function loadInfo(city) {
		var path = "jgp/res/citys.png";//保存城市列表信息的文件路径
		var cityName1='';
		var cityCode1='';
    $.getJSON(path, function(data) {
        $.each(data.citys, function(i, item) {
			var cityName=item.name;
			var cityCode = item.code;
			if(cityName.indexOf(city) >= 0 ) {
				if(cityCode=="PVG"){
					cityName='SHA 上海虹桥';
					cityCode='SHA';
				}
				cityName1=cityName.substring(4,cityName.length);
				city1=cityCode;
			}
        });
		if(city==null||city==""){
			city1 = "默认SHA";
		}
				
		$$("qifei").innerHTML = cityName1;
		$$("qifei1").innerHTML = city1;
        });
}

function isDefine(para) {
	if (typeof para == 'undefined' || para == '[]' || para == "" || para == null || para == 'null' || para == "NaN" || para == undefined)              return false;
	else  return true;
};
//获取掌上东航的账号（用户编号、用户密码）							
	var varUserCode = "";
	//    var varPassword = "";
	var localLoginInfor = localStorage.getItem("MU30-USERINFO");
	if (isDefine(localLoginInfor)) {
		var objLocalUserInfor = JSON.parse(localLoginInfor);
		for (var i in objLocalUserInfor) {
			var item = objLocalUserInfor[i];
			if (item) {
				varUserCode = objLocalUserInfor.username;
				setStorage("submitMan",varUserCode);
				//                varPassword = objLocalUserInfor.password;
			}
		}
	}